Repository navigation
Conversation
getStatObjects rasterized the zone at the full extent of the input raster and then read and scanned every pixel, so the cost scaled with raster size rather than with the size of the region of interest. For a small polygon on a large raster this is both slow and memory-hungry (two full-size sample arrays). Rasterize the ROI with useGeometryExtent=true so only the window covered by the geometry is produced, and read just that window from the source band. The window's offset in the source raster is computed from pixel centres. If the window cannot be placed exactly (for example a skewed raster or a window that does not fit inside the raster), fall back to the previous full-extent path, so results are unchanged in those cases. A null rasterization result (the geometry burns no pixel) now yields an empty pixel set, matching the previous behaviour. Statistics are unchanged: pixels are still visited in row-major order, so the output of RS_ZonalStats and RS_ZonalStatsAll is identical to before. Tests: - [new tests: small polygon on a larger raster, bottom-up raster, polygon that only touches the raster boundary] - RasterBandAccessorsTest passes Benchmark ([machine, JDK], [size] raster, ~50x50 pixel polygon): before [x] ms, after [y] ms Closes apache#2409
|
@modi3011 test failed, please take a look |
|
Hi @jiayuasu. Sorry for the failing tests in the last commit. Can you please take another look at the latest commit? |
|
Nice improvement. Rasterizing only the ROI's window instead of the whole raster means zonal stats now scale with the size of the zone rather than the raster, which is exactly what #2409 asks for. Thanks for the quick fix on the RasterizationTest cases too. |
|
@modi3011 can you check your pr description? It has lots of place holder and does not make sense. |
|
and your pr does not have any test. not sure if this is expected |
Cover a small polygon on a larger raster (top-down and bottom-up), a polygon partly outside the raster, nodata exclusion inside the window, and a polygon that only touches the raster boundary.
|
Thanks @jiayuasu for pointing this out. I apologize for the frequent changes related to the PR and the description. I've fixed the description. I've also added tests to RasterBandAccessorsTest covering a small polygon on a larger raster (top-down and bottom-up), a polygon partly outside the raster, nodata inside the window, and a polygon that only touches the boundary. They also pass against the previous implementation, so the results are unchanged. |
|
Nice, the tests cover the edge cases, including the polygon only touching the boundary and the one partly outside the raster. lgtm |
|
Thanks for adding these. Running the new tests against the previous implementation as well is a nice touch, since it shows the clipped window gives exactly the same results as before, and the bottom-up raster and allTouched cases make the coverage solid. The updated description reads clearly too. Looks good to me 👍 |
|
after reviewing this pr, i think there are a number of correctness issue of this pr. Please do not work on issues that are not marked as good first issue. Thanks. |
|
Thanks for taking the time to review the PR. I know that there may be some correctness issues that need to be addressed. I’ll make sure to focus only on issues marked as good first issues and avoid working on anything outside that scope. I’d also appreciate it if you could point out what I could have done differently while working on this PR, or any specific areas where I could improve my approach. I’d love to learn from this experience and do better in future contributions. |
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes [Sedona Core] Sedona doesn't clip raster to geometry extent in zonal statistics which can lead to inefficient queries #2409What changes were proposed in this PR?
getStatObjects(used byRS_ZonalStatsandRS_ZonalStatsAll) rasterized the ROI at the full extent of the input raster, read two full-size sample arrays, and scanned every pixel, so the cost grew with the raster rather than with the region of interest.This PR rasterizes only the window covered by the ROI (
useGeometryExtent=true) and reads just that window from the source band.RasterizationTestexercises.nullrasterization result (the geometry burns no pixel) yields an empty pixel set, as before.Pixels are still visited in row-major order, so the output is unchanged.
How was this patch tested?
testZonalStatsSmallPolygonOnLargerRaster,testZonalStatsPolygonPartlyOutsideRaster,testZonalStatsNoDataInsideClippedWindowandtestZonalStatsPolygonOnlyTouchingRasterBoundarytoRasterBandAccessorsTest. They use a raster with distinct pixel values and a window that does not start at the raster's origin, and cover top-down and bottom-up rasters,allTouchedtrue and false, and nodata.RasterBandAccessorsTestandRasterizationTestpass.Did this PR include necessary documentation updates?